<template>
  <div class="detectionReferenceList padding_20">
    <el-input v-model="param.name"
              placeholder="请输入名称"
              class="w-200"
              clearable
              @clear="handleQuery"/>
    <el-button type="primary"
               @click="handleQuery">查 询
    </el-button>
    <el-button type="primary"
               @click="handleAdd">新 增
    </el-button>
    <Table border
           stripe
           :columns="tableCol"
           :data="tableData"
           class="mt-20">
      <template slot-scope="{row,index}"
                slot="action">
        <span @click="handleView(row)">详细</span>
        <span @click="handleEdit(row)">编辑</span>
<!--        <span @click="handleCondition(row)">特殊条件判断配置</span>-->
        <span @click="handleDel(row)">删除</span>
      </template>
    </Table>
    <page @getList="_getList"
          :pageTotal="pageTotal"
          ref="page"></page>
    <detectionReferenceEdit ref="detectionReferenceEdit"
                            @getList="_getList"></detectionReferenceEdit>
    <detectionReferenceView ref="detectionReferenceView"></detectionReferenceView>
    <dialog-conditon v-if="showDialog" :visible.sync="showDialog" :dataObj="dataObj"/>
  </div>
</template>

<script>

  import Page from '@/base/page/page'
  import {mapGetters} from 'vuex'
  import DetectionReferenceEdit from './detectionReferenceEdit'
  import DetectionReferenceView from './detectionReferenceView'
  import dialogConditionConfig from "./dialogConditionConfig";

  export default {
    name: "detectionReferenceList",
    data() {
      return {
        dataObj:{},
        showDialog:false,
        tableCol: [
          {
            type: 'index2',
            title: '',
            width: 60,
            render: (h, params) => {
              return h('span', params.index + (this.page.pageIndex) * this.page.pageSize + 1);
            }
          },
          {
            title: '名称',
            key: 'name'
          },
          {
            title: 'code',
            key: 'code'
          },
          {
            title: '内容',
            key: 'content'
          },
          {
            title: '检测结果判断',
            key: 'criterion'
          },
          {
            title: '创建时间',
            key: 'createTime',
            width: 150,
            render: (h, params) => {
              return h('span',
                this.commonFunction.timestampFormat(new Date(params.row.createTime), 'yyyy-MM-dd hh:mm'));
            }
          },
          {
            title: '操作',
            slot: 'action',
            align: 'center'
          }
        ],
        tableData: [],
        pageTotal: 0,       //总条数
        wdStudioTypeList: [],
        hospitalList: [],
        loading: false,
        param: {
          name: ''
        }
      }
    },
    mounted() {
      if (this.params.detectionReferenceList) {
        this.param = this.params.detectionReferenceList
      } else {
        this.$store.commit('SET_PARAMS', {detectionReferenceList: this.param})
      }
      this._getList()
    },
    methods: {
      handleQuery() {
        this.page.pageIndex = 0
        this._getList()
      },
      handleView(row) {
        this.$refs.detectionReferenceView.openView(row)
      },
      handleEdit(row) {
        this.$refs.detectionReferenceEdit.openView(row)
      },
      handleCondition(row) {
        this.showDialog=true
        this.dataObj=row
      },
      handleAdd() {
        this.$refs.detectionReferenceEdit.openView()
      },
      handleDel(row) {
        this.$Modal.confirm({
          title: '确认',
          content: '<p>您确认删除该检测指标？</p>',
          onOk: () => {
            this.ajax({
              type: this.api.detectionReferenceDel.type,
              url: this.api.detectionReferenceDel.url,
              isDel: true,
              data: {
                id: row.id,
              },
              success: (data) => {
                this.$Message.success('删除成功！');
                this._getList()
              },
              error: (data) => {
                this.$Message.error(data.message);
              }
            })
          },
          onCancel: () => {
          }
        });
      },
      _getList() {
        this.ajax({
          type: this.api.detectionReferenceList.type,
          url: this.api.detectionReferenceList.url,
          data: Object.assign({}, this.page, this.param),
          success: (data) => {
            this.tableData = data.object
            this.pageTotal = data.totalNum
            this.$previewRefresh()
          },
          error: (data) => {
            this.$Message.error(data.message);
          }
        })
      }
    },
    computed: {
      ...mapGetters([
        'page',
        'params'
      ])
    },
    components: {
      Page,
      DetectionReferenceEdit,
      DetectionReferenceView,
      'dialog-conditon':dialogConditionConfig
    }
  }
</script>

<style lang="scss" type="text/scss" rel="stylesheet/scss">
  .detectionReferenceList {
  }

  .ivu-table-cell {
    white-space: nowrap;
    overflow: hidden;
  }
</style>
